package com.lebron.kotlin.ui.fragment

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.gyf.barlibrary.ImmersionBar

/**
 * @Author lebron
 * @Date 18-7-24-下午1:58
 * 
 */
abstract class BaseFragment : Fragment() {

    val TAG = javaClass.simpleName

    private var mView: View? = null

    //状态栏信息
    open var immersionBar: ImmersionBar? = null

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        mView = inflater.inflate(getLayoutId(), container, false)

        return mView
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        if(isImmersionBar()){
            initImersionBar()
        }
        initView()

        if (!isHidden) initData()
    }

    abstract fun initData()

    abstract fun initView()

    abstract fun getLayoutId(): Int


    override fun onDestroy() {
        super.onDestroy()
        immersionBar?.destroy()
    }

    open fun isImmersionBar(): Boolean = true//是否使用沉浸式状态栏

    private fun initImersionBar() {
        immersionBar = ImmersionBar.with(this)
        immersionBar?.init()
    }
}